<?php
namespace app\mobile\controller;


use app\model\model\Ad;
use app\model\model\Application;
use app\model\model\Free_tags;
use app\model\model\Nav;
use app\model\model\News;
use app\model\model\Partners;
use app\model\model\Seo;
use app\model\model\Setup;
use app\model\model\Social;
use app\model\model\Subscription;
use app\model\model\Video;
use app\model\model\Visiting;
use think\Request;

class Index extends Base
{
    //实例化

    protected $_Seo;
    protected $_Ad;
    protected $_visiting;
    protected $_blog;
    protected $_video;
    protected $_Freetags;
    protected $_Setup;
    protected $_Social;
    protected $_Product;
    protected $_Applications;
    protected $_Partners;
    public function __construct(Request $request = null){
        parent::__construct($request);


        $this->_Ad = new Ad();
        $this->_visiting = new Visiting();
        $this->_blog = new News();
        $this->_video = new Video();
        $this->_Seo = new Seo();
        $this->_Freetags = new Free_tags();
        $this->_Product = new \app\model\model\Product();
        $this->_Applications = new Application();
        $this->_Partners = new Partners();
        $this->_Setup = new Setup();
    }

    public function index(){

       
        $setup = $this->_Setup->getOne(1);
        $this->assign('setuo',$setup);
        //SEO
        $seo = $this->_Seo->getOne(['id'=>1]);
        $this->assign('seo',$seo);

        //首页顶部banner
        $banner = $this->_Ad->getListHome(['type_id'=>33,'flag'=>1]);
        $this->assign('banner',$banner);
        //客户来访
        $visiting = $this->_visiting->getListHome(['flag'=>1],6);
        $this->assign('visiting',$visiting);
        //博客
        $blog = $this->_blog->getListHome(['classify'=>2,'flag'=>1],3);
        foreach ($blog as $v){
            $v['create_time'] = date('m, Y',$v['create_time']);
            $v['uname'] = str_replace(" ","-",$v['name']);
        }
        $this->assign('blog',$blog);
        //中间视频
        $vurl = $this->_video->getOne(5);
        $vurl['uname'] = str_replace(" ","-",$vurl['name']);
        $this->assign('vurl',$vurl);
        //下方视频
        $video = $this->_video->getListHome(['flag'=>1],3);
        foreach ($video as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['create_time'] = date('m, Y',$v['create_time']);
        }
        $this->assign('video',$video);
        //OREE LASER
        $OREE_LASER['one'] = $this->_Freetags->getOne(23);
        $OREE_LASER['two'] = $this->_Freetags->getOne(24);
        $OREE_LASER['three'] = $this->_Freetags->getOne(25);
        $this->assign('OREE_LASER',$OREE_LASER);
        //首页Banner下面介绍信息
        $com_intro['one'] = $this->_Freetags->getOne(26);
        $com_intro['two'] = $this->_Freetags->getOne(27);
        $com_intro['three'] = $this->_Freetags->getOne(28);
        $this->assign('com_intro',$com_intro);
        //首页中间的关于我们
        $ABOUT_US_OREE_LASER = $this->_Freetags->getOne(29);
        $this->assign('ABOUT_US_OREE_LASER',$ABOUT_US_OREE_LASER);
        //首页产品轮播
        $productlist = $this->_Product->getListSelect(['flag'=>1],true,4);
        foreach ($productlist as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['img'] = json_decode($v['tel_img'],true);
        }
        $this->assign('prolist',$productlist);
        //应用
        $app = $this->_Applications->getListSelect(['flag'=>1],true,4);
        foreach ($app as $v){
            $v['uname'] = str_replace(" ","-",$v['name']);
            $v['img_url'] = json_decode($v['img_url'],true);

        }

        $this->assign('app',$app);
        //合作伙伴
        $partners = $this->_Partners->getListHome([],6);
        $this->assign('partners',$partners);
        return $this->fetch();
    }
    //底部订阅添加
    public function subscription(){
        $subscription = new Subscription();
        $data = [
            'email'=>input('email'),
            'create_time'=>time(),
            'laiyuan'=>2
        ];
        $re = $subscription->add($data);
        if($re){
            return json_echo_msg(200,'提交成功!');
        }else{
            return json_echo_msg(500,'');
        }

    }
}
